package yingyong;

import gongju.DBUtil;
import pickaging.HouseInfo;
import pickaging.HouseType;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/add")
public class Add extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf8");
        response.setContentType("text/html;charset=utf8");
        String sql = "select * from house_type;";
        try {
            ResultSet re = DBUtil.query(sql);
            ArrayList<HouseType> list = new ArrayList<>();
            while (re.next()){
                int id = re.getInt("id");
                String type = re.getString("type");
                HouseType ht = new HouseType(id, type);
                list.add(ht);
            }
            request.setAttribute("list",list);
            request.getRequestDispatcher("WEB-INF/add.jsp").forward(request,response);
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
